﻿<%@ Page Title="Анализ :: Адресная программа" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AP.aspx.cs" Inherits="Analysis.AP" %>
<%@ Register TagName="CustomColumnDialog" Src="~/Controls/CustomColumnDialog.ascx" TagPrefix="analysis"  %>
<%@ Register TagName="ExcelImportDialog" Src="~/Controls/ExcelImportDialog.ascx" TagPrefix="analysis"  %>
<%@ Register TagName="ExcelImportErrorList" Src="~/Controls/ExcelImportErrorList.ascx" TagPrefix="analysis"  %>
<%@ Register TagName="ExcelImportColumnErrorList" Src="~/Controls/ExcelImportColumnErrorList.ascx" TagPrefix="analysis"  %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        var autoCity = "";
        var autoRegion = "";

        $(function () {
            
            Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function (evt, args) {
                $('.mightOverflow').bind('mouseenter', function () {
                    var $this = $(this);

                    if (this.offsetWidth < this.scrollWidth && !$this.attr('title')) {
                        $this.attr('title', $this.attr('data-overflow-title'));
                    }
                });
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="page_header">
        <h2><img src="<%=ResolveClientUrl("~") %>images/design/contract_tt_icon.png" alt="" title="" /> Адресная программа</h2>
    </div>
            
			<asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
        	<div class="page_container">
                <div class="table-responsive" style="overflow-x:auto;width:100%;margin-top: -30px;">
                <asp:GridView ID="grid" AutoGenerateColumns="false" runat="server" CssClass="grid-table table table-bordered table-hover" DataKeyNames="APId"
                AllowSorting="true" OnSorting="grid_Sorting" 
                AllowPaging="True" PageSize="20" OnPageIndexChanging="grid_PageIndexChanging"
                OnRowDataBound="grid_RowDataBound" OnRowCommand="grid_RowCommand"
                OnRowCreated="grid_RowCreated" OnPreRender="grid_PreRender">
                <PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" PageButtonCount="4" NextPageText=">" PreviousPageText="<"  FirstPageText="первая" LastPageText="последняя"/>
                <Columns>
                    <asp:TemplateField HeaderText=""> 
                        <HeaderTemplate><asp:CheckBox runat="server" ID="chbSelectAll" AutoPostBack="true" OnCheckedChanged="SelectAll_CheckedChange" /></HeaderTemplate>
                        <ItemTemplate> 
                            <asp:CheckBox runat="server" ID="chbIsSelected" Checked='<%# Bind("IsSelected") %>' AutoPostBack="true" OnCheckedChanged="selected_CheckedChange" />
                       </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Id"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblClientIdField" Text="ClientId" Visible="false"/></HeaderTemplate>
                        <ItemTemplate> 
                            <asp:TextBox ID="txtClientId" runat="server" Text='<%# Bind("ClientId") %>' CssClass="form-control" placeholder="Введите Id" ValidationGroup="updateItem"></asp:TextBox> 
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" ControlToValidate="txtClientId" runat="server" Text="*" ValidationGroup="updateItem" CssClass="validation_message" Enabled="false" Display="Dynamic" />
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtClientId" Text="Требуется целое число" ValidationGroup="updateItem" CssClass="validation_message" ValidationExpression="[0-9]{1,10}" Enabled="false" Display="Dynamic" />
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Регион">
                        <HeaderTemplate><asp:Label runat="server" ID="lblRegionNameField" Text="RegionName" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:TextBox ID="txtRegionName" runat="server" Text='<%# Bind("RegionName") %>' CssClass="form-control" placeholder="Введите название региона" ValidationGroup="updateItem"></asp:TextBox> 
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator6" ControlToValidate="txtRegionName" runat="server" Text="*" ValidationGroup="updateItem" CssClass="validation_message" Display="Dynamic" />
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Город"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblCityNameField" Text="CityName" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:TextBox ID="txtCityName" runat="server" Text='<%# Bind("CityName") %>' CssClass="form-control" placeholder="Введите название города" ValidationGroup="updateItem"></asp:TextBox> 
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator7" ControlToValidate="txtCityName" runat="server" Text="*" ValidationGroup="updateItem" CssClass="validation_message" Display="Dynamic" />
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Название"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblSalePointNameField" Text="SalePointName" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:TextBox ID="txtSalePointName" runat="server" Text='<%# Bind("SalePointName") %>' CssClass="form-control" placeholder="Введите название торговой точки" ValidationGroup="updateItem"></asp:TextBox> 
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator9" ControlToValidate="txtSalePointName" runat="server" Text="*" ValidationGroup="updateItem" CssClass="validation_message" Display="Dynamic" />
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Юридическое название"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblSalePointJurNameField" Text="SalePointJurName" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:TextBox ID="txtSalePointJurName" runat="server" Text='<%# Bind("SalePointJurName") %>' CssClass="form-control" placeholder="Введите юридическое название торговой точки" ValidationGroup="updateItem"></asp:TextBox> 
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Адрес"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblAddressField" Text="Address" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:TextBox ID="txtAddress" runat="server" Text='<%# Bind("Address") %>' CssClass="form-control" placeholder="Введите адрес торговой точки" ValidationGroup="updateItem" Display="Dynamic" />
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Канал"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblSaleChannelNameField" Text="SaleChannelName" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:DropDownList ID="ddlSaleChannelId" runat="server" DataTextField="SaleChannelName" DataValueField="SaleChannelId" ValidationGroup="updateItem"  CssClass="form-control"/>
                            <asp:CompareValidator id="CompareValidator1" runat="server" ControlToValidate="ddlSaleChannelId" ValidationGroup="updateItem" ErrorMessage="*" Operator="NotEqual" ValueToCompare="-1" CssClass="validation_message" Enabled="false" Display="Dynamic"/>
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Кол-во ТТ"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblTTQtyField" Text="TTQty" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:TextBox ID="txtTTQty" runat="server" Text='<%# Bind("TTQty") %>' CssClass="form-control" placeholder="Введите кол-во ТТ" ValidationGroup="updateItem"></asp:TextBox> 
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator11" ControlToValidate="txtTTQty" runat="server" Text="*" ValidationGroup="updateItem" CssClass="validation_message" Display="Dynamic" Enabled="false" />
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="txtTTQty" Text="Требуется целое число" ValidationGroup="updateItem" CssClass="validation_message" ValidationExpression="[0-9]{1,10}" Display="Dynamic" />
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Формат"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblStorePointNameField" Text="StorePointName" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:DropDownList ID="ddlStorePointId" runat="server" DataTextField="StorePointName" DataValueField="StorePointId" ValidationGroup="updateItem"  CssClass="form-control"/>
                            <asp:CompareValidator id="CompareValidator3" runat="server" ControlToValidate="ddlStorePointId" ValidationGroup="updateItem" ErrorMessage="*" Operator="NotEqual" ValueToCompare="-1" CssClass="validation_message" Enabled="false" Display="Dynamic"/>
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Depart1"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblDepart1UserNameField" Text="Depart1UserName" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:DropDownList ID="ddlDepart1UserId" runat="server" DataTextField="FullName" DataValueField="Id" ValidationGroup="updateItem"  CssClass="form-control"/>
                            <asp:CompareValidator id="CompareValidator5" runat="server" ControlToValidate="ddlDepart1UserId" ValidationGroup="updateItem" ErrorMessage="*" Operator="NotEqual" ValueToCompare="-1" CssClass="validation_message" Enabled="false" Display="Dynamic"/>
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Depart2"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblDepart2UserNameField" Text="Depart2UserName" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:DropDownList ID="ddlDepart2UserId" runat="server" DataTextField="FullName" DataValueField="Id" ValidationGroup="updateItem"  CssClass="form-control"/>
                            <asp:CompareValidator id="CompareValidator7" runat="server" ControlToValidate="ddlDepart2UserId" ValidationGroup="updateItem" ErrorMessage="*" Operator="NotEqual" ValueToCompare="-1" CssClass="validation_message" Enabled="false" Display="Dynamic"/>
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Depart3"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblDepart3UserNameField" Text="Depart3UserName" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:DropDownList ID="ddlDepart3UserId" runat="server" DataTextField="FullName" DataValueField="Id" ValidationGroup="updateItem"  CssClass="form-control"/>
                            <asp:CompareValidator id="CompareValidator9" runat="server" ControlToValidate="ddlDepart3UserId" ValidationGroup="updateItem" ErrorMessage="*" Operator="NotEqual" ValueToCompare="-1" CssClass="validation_message" Enabled="false" Display="Dynamic"/>
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Depart4"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblDepart4UserNameField" Text="Depart4UserName" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:DropDownList ID="ddlDepart4UserId" runat="server" DataTextField="FullName" DataValueField="Id" ValidationGroup="updateItem"  CssClass="form-control"/>
                            <asp:CompareValidator id="CompareValidator11" runat="server" ControlToValidate="ddlDepart4UserId" ValidationGroup="updateItem" ErrorMessage="*" Operator="NotEqual" ValueToCompare="-1" CssClass="validation_message" Enabled="false" Display="Dynamic"/>
                        </ItemTemplate> 
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Depart5"> 
                        <HeaderTemplate><asp:Label runat="server" ID="lblDepart5UserNameField" Text="Depart5UserName" Visible="false"/></HeaderTemplate> 
                        <ItemTemplate> 
                            <asp:DropDownList ID="ddlDepart5UserId" runat="server" DataTextField="FullName" DataValueField="Id" ValidationGroup="updateItem"  CssClass="form-control"/>
                            <asp:CompareValidator id="CompareValidator13" runat="server" ControlToValidate="ddlDepart5UserId" ValidationGroup="updateItem" ErrorMessage="*" Operator="NotEqual" ValueToCompare="-1" CssClass="validation_message" Enabled="false"/>
                        </ItemTemplate> 
                    </asp:TemplateField>
               
                    <asp:TemplateField HeaderText="Действия" Visible="false">
                        <ItemTemplate>
                            <asp:LinkButton ID="lnkDelete" runat="server" CommandName="MakeDelete" Text="Удалить" CommandArgument='<%# Eval("APId")%>' OnClientClick="if (Page_ClientValidate('updateItem')) {return confirm('Подтвердите удаление АП');} else {return false;}" ValidationGroup="updateItem"></asp:LinkButton> 
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                </asp:GridView>
                </div>
                <asp:Button CssClass="btn apps_btn apps_gray_btn" ID="btnAddAP" Text="Добавить" runat="server" OnClick="btnAddAP_Click"/>
                <asp:Button CssClass="btn apps_btn apps_gray_btn" ID="btnSaveAP" Text="Сохранить изменения" runat="server" ValidationGroup="updateItem" onclick="btnSaveAP_Click" />
                <asp:Button CssClass="btn apps_btn apps_gray_btn" ID="btnDeleteSelected" Text="Удалить выбранные строки" runat="server" OnClientClick="if (Page_ClientValidate('updateItem')) {return confirm('Подтвердите удаление выбранных строк');} else {return false;}" OnClick="btnDeleteSelected_Click" />
                <asp:Button CssClass="btn apps_btn apps_gray_btn" ID="btnExcelImport" Text="Импорт из Excel" runat="server" OnClientClick="openExcelImportDialog(); return false;" />
                <asp:Button CssClass="btn apps_btn apps_gray_btn" ID="btnExcelExport" Text="Экспорт в Excel" runat="server" OnClick="btnExcelExport_Click" />
                <asp:Button CssClass="btn apps_btn apps_gray_btn" ID="btnCustomColumn" Text="Конструктор адресной программы" runat="server" OnClientClick="showCustomColumn(); return false;" Visible="False" />
            </div>
            
            </ContentTemplate>
            <Triggers>
                <asp:PostBackTrigger ControlID="btnExcelExport" />
            </Triggers>
            </asp:UpdatePanel>
            
            <analysis:CustomColumnDialog ID="ctrlCustomColumnDialog"  runat="server" AllowAdd="true" AllowVisible="false" />
            <analysis:ExcelImportDialog ID="ctrlExcelImportDialog"  runat="server" />
            <analysis:ExcelImportErrorList ID="ctrlExcelImportErrorList"  runat="server" />
            <analysis:ExcelImportColumnErrorList ID="ctrlExcelImportColumnErrorList"  runat="server" />
</asp:Content>
